# 用户修改性别————updUserSex
@app.route("/updUserSex", methods=['GET', 'POST'])
def updUserSex():

    data = request.get_data()
    json_data = json.loads(data.decode("UTF-8"))
    sex = json_data.get("sex")
    #print(sex)
    openid = json_data.get("openid")
    if sex != '男' and sex != "女":
        return jsonify({"status": 500, "msg": "error!请填写男或女作为自己的性别"})
    db = pymysql.connect(host="localhost",
                         user="root",
                         password="123456",
                         database="ayh",
                         charset="utf8")
    #print("database yes")
    cursor = db.cursor()
    sql = 'UPDATE users SET sex = %s  WHERE openid = %s'
    cursor.execute(sql, (sex, openid))
    db.commit()
    cursor.close()
    db.close()
    return jsonify({"status": 200, "sex": sex})
    # return jsonify({"status": 200, "sex": sex})
    # except Exception as e:
    #     print("查询出错: " + e)
    #     db.rollback()
    #     cursor.close()
    #     db.close()
    #     return jsonify({"status": 500, "msg": "error"})


# 用户修改手机号————updUserPhone
@app.route("/updUserPhone", methods=['PUT'])
def updUserPhone():
    data = request.get_data()
    json_data = json.loads(data.decode("UTF-8"))
    phone = json_data.get("phone")
    #print(phone)
    openid = json_data.get("openid")
    if len(phone) != 11:
        return jsonify({"status": 500, "msg": "error请填写正确的11位手机号码"})
    db = pymysql.connect(host="localhost",
                         user="root",
                         password="123456",
                         database="ayh",
                         charset="utf8")
    #print("database yes")
    cursor = db.cursor()
    sql = 'UPDATE users SET phone = %s  WHERE openid = %s'
    cursor.execute(sql, (phone, openid))
    db.commit()
    cursor.close()
    db.close()
    return jsonify({"status": 200, "phone": phone})
    # return jsonify({"status": 200, "sex": sex})
    # except Exception as e:
    #     print("查询出错: " + e)
    #     db.rollback()
    #     cursor.close()
    #     db.close()
    #     return jsonify({"status": 500, "msg": "error"})